<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="人员姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="证件类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择证件类型" clearable>
          <el-option
            v-for="dict in dict.type.sys_idcard_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="证件号码" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号/电话号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="记录人" prop="recorder">
        <el-input
          v-model="queryParams.recorder"
          placeholder="请输入记录人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="输入时间" prop="inputDate">
        <el-date-picker clearable
          v-model="queryParams.inputDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择输入时间"
          style="width: 203px" >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="输入地点" prop="inputPosition">
        <el-input
          v-model="queryParams.inputPosition"
          placeholder="请填写输入地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体温" prop="temperature">
        <el-input
          v-model="queryParams.temperature"
          placeholder="请输入体温"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核酸检测" prop="isNucleicCheck">
        <el-input
          v-model="queryParams.isNucleicCheck"
          placeholder="请输入是否核酸检测"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="核酸结果" prop="nucleicResult">
        <el-input
          v-model="queryParams.nucleicResult"
          placeholder="请输入核酸检测结果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来自省份" prop="fromProvince">
        <el-select v-model="queryParams.fromProvince" placeholder="请选择来自省份" clearable @change=queryProvinceChange()>
          <el-option
            v-for="p in provinceList"
            :key="p.areaId"
            :label="p.areaName"
            :value="p.areaId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="来自某市" prop="fromCity">
        <el-select v-model="queryParams.fromCity" placeholder="请选择来自某市" clearable @change=queryCityChange()>
          <el-option
            v-for="city in cityList"
            :key="city.areaId"
            :label="city.areaName"
            :value="city.areaId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="来自某区" prop="fromDistrict">
        <el-select v-model="queryParams.fromDistrict" placeholder="请选择来自某区" clearable>
          <el-option
            v-for="area in districtList"
            :key="area.areaId"
            :label="area.areaName"
            :value="area.areaId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="风险区?" prop="isRiskArea">
        <el-select v-model="queryParams.isRiskArea" placeholder="请选择是否来自风险区" clearable>
          <el-option
            v-for="dict in dict.type.yes_or_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="现住地址" prop="nowAddress">
        <el-input
          v-model="queryParams.nowAddress"
          placeholder="请输入现居住地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接收时间" prop="finishDate">
        <el-date-picker clearable
          v-model="queryParams.finishDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择接收完毕时间" style="width: 203px">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否确诊" prop="ifDiagnosis">
        <el-select v-model="queryParams.ifDiagnosis" placeholder="请选择是否确诊" clearable>
          <el-option
            v-for="dict in dict.type.yes_or_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否密接" prop="ifCloseContact">
        <el-select v-model="queryParams.ifCloseContact" placeholder="请选择是否密接" clearable>
          <el-option
            v-for="dict in dict.type.yes_or_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <hr/>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['eim:citizen:add']"
        >外部输入人员新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['eim:citizen:edit']"
        >外部输入人员修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['eim:citizen:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['eim:citizen:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 屏幕下部数据展示-->
    <el-table v-loading="loading" :data="citizenList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="居民ID" align="center" prop="pid" width="60"/>
      <el-table-column label="姓名" align="center" prop="name" width="80"/>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="证件类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_idcard_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="证件号码" align="center" prop="idCard" width="180" />
      <el-table-column label="手机号/电话号" align="center" prop="phone" width="120"/>
      <el-table-column label="记录人" align="center" prop="recorder" />
      <el-table-column label="输入时间" align="center" prop="inputDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inputDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="输入地点" align="center" prop="inputPosition" width="130"/>
      <el-table-column label="体温" align="center" prop="temperature" width="80"/>
      <el-table-column label="是否核酸检测" align="center" prop="isNucleicCheck" />
      <el-table-column label="核酸检测结果" align="center" prop="nucleicResult">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.nucleicResult"/>
        </template>
      </el-table-column>
      <el-table-column label="来自省份" align="center" prop="fromProvince">
        <template slot-scope="scope">
          <dict-tag :options="provinceList" :value="scope.row.fromProvince.areaName"/>
        </template>
      </el-table-column>
      <el-table-column label="来自某市" align="center" prop="fromCity">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.fromCity"/>
        </template>
      </el-table-column>
      <el-table-column label="来自某区" align="center" prop="fromDistrict">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_notice_type" :value="scope.row.fromDistrict"/>
        </template>
      </el-table-column>
      <el-table-column label="是否来自风险区" align="center" prop="isRiskArea">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_or_no" :value="scope.row.isRiskArea"/>
        </template>
      </el-table-column>
      <el-table-column label="是否居家健康隔离" align="center" prop="isHomeDivide" />
      <el-table-column label="现居留某省" align="center" prop="nowProvince" />
      <el-table-column label="现居留某市" align="center" prop="nowCity" />
      <el-table-column label="现居留某区" align="center" prop="nowDistrict" />
      <el-table-column label="现居住地址" align="center" prop="nowAddress" width="220"/>
      <el-table-column label="负责社区" align="center" prop="chargeDist" />
      <el-table-column label="负责联系人" align="center" prop="chargeStaff" />
      <el-table-column label="是否接收完毕" align="center" prop="isFinish" />
      <el-table-column label="接收完毕时间" align="center" prop="finishDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否确诊" align="center" prop="ifDiagnosis">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_or_no" :value="scope.row.ifDiagnosis"/>
        </template>
      </el-table-column>
      <el-table-column label="是否密接" align="center" prop="ifCloseContact">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yes_or_no" :value="scope.row.ifCloseContact"/>
        </template>
      </el-table-column>
      <el-table-column label="管控状态" align="center" prop="controlStatus" />
      <el-table-column label="户籍省份" align="center" prop="originProvince" />
      <el-table-column label="户籍城市" align="center" prop="originCity" />
      <el-table-column label="户籍某区" align="center" prop="originArea" />
      <el-table-column label="户籍所在地址" align="center" prop="originAddress" width="200"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['eim:citizen:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['eim:citizen:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改外部输入人员对话框 新增-->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择证件类型">
            <el-option
              v-for="dict in dict.type.sys_idcard_type"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号/电话号" />
        </el-form-item>

        <el-form-item label="输入时间" prop="inputDate">
          <el-date-picker clearable
            v-model="form.inputDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="体温" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入体温" />
        </el-form-item>
        <el-form-item label="核酸检测" prop="isNucleicCheck">
          <el-input v-model="form.isNucleicCheck" placeholder="请输入是否核酸检测:1-检测;0-未检测" />
        </el-form-item>


      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">新增确定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--    //下面是修改-->
    <!-- 添加或修改外部输入人员对话框 -->
    <el-dialog :title="title_1" :visible.sync="open_1" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择证件类型">
            <el-option
              v-for="dict in dict.type.sys_idcard_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号/电话号" />
        </el-form-item>
        <el-form-item label="记录人" prop="recorder">
          <el-input v-model="form.recorder" placeholder="请输入记录人" />
        </el-form-item>
        <el-form-item label="输入时间" prop="inputDate">
          <el-date-picker clearable
                          v-model="form.inputDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="体温" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入体温" />
        </el-form-item>
        <el-form-item label="核酸检测" prop="isNucleicCheck">
          <el-input v-model="form.isNucleicCheck" placeholder="请输入是否核酸检测:1-检测;0-未检测" />
        </el-form-item>

        <hr/>
        <el-tag type="danger" style="font-size: 15px">以下由社区工作人员填写</el-tag> <br/>

        <el-form-item label="核酸结果" prop="nucleicResult">
          <el-input v-model="form.nucleicResult" placeholder="请输入核酸检测结果" />
        </el-form-item>

        <el-form-item label="来自省份" prop="fromProvince">
          <el-select v-model="form.fromProvince" placeholder="请选择来自省份" clearable @change=formProvinceChange()>
            <el-option
              v-for="p in provinceList"
              :key="p.areaId"
              :label="p.areaName"
              :value="p.areaId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="来自某市" prop="fromCity">
          <el-select v-model="form.fromCity" placeholder="请选择来自某市" @change="formCityChange()">
            <el-option
              v-for="city in formCityList"
              :key="city.areaId"
              :label="city.areaName"
              :value="city.areaId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="来自某区" prop="fromDistrict">
          <el-select v-model="form.fromDistrict" placeholder="请选择来自某区">
            <el-option
              v-for="district in formDistrictList"
              :key="district.areaId"
              :label="district.areaName"
              :value="district.areaId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="风险区?" prop="isRiskArea">
          <el-select v-model="form.isRiskArea" placeholder="请选择是否来自风险区">
            <el-option
              v-for="dict in dict.type.yes_or_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>


          <el-form-item label="现居某省" prop="nowProvince">
            <el-select v-model="form.nowProvince" placeholder="请选择现居留省份" clearable @change=formProvinceChange()>
              <el-option
                v-for="p in provinceList"
                :key="p.areaId"
                :label="p.areaName"
                :value="p.areaId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="现居某市" prop="nowCity">
            <el-select v-model="form.nowCity" placeholder="请选择现居留某市" @change="formCityChange()">
              <el-option
                v-for="city in formCityList"
                :key="city.areaId"
                :label="city.areaName"
                :value="city.areaId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="现居某区" prop="nowDistrict">
            <el-select v-model="form.nowDistrict" placeholder="请选择现居留某区">
              <el-option
                v-for="district in formDistrictList"
                :key="district.areaId"
                :label="district.areaName"
                :value="district.areaId"
              />
            </el-select>
          </el-form-item>


        <el-form-item label="现居地址" prop="nowAddress">
          <el-input v-model="form.nowAddress" placeholder="请输入现居住地址" />
        </el-form-item>
        <el-form-item label="接收时间" prop="finishDate">
          <el-date-picker clearable
                          v-model="form.finishDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择接收完毕时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否确诊" prop="ifDiagnosis">
          <el-select v-model="form.ifDiagnosis" placeholder="请选择是否确诊">
            <el-option
              v-for="dict in dict.type.yes_or_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否密接" prop="ifCloseContact">
          <el-select v-model="form.ifCloseContact" placeholder="请选择是否密接">
            <el-option
              v-for="dict in dict.type.yes_or_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="管控状态" prop="controlStatus">
          <el-select v-model="form.controlStatus" placeholder="请选择管控状态">
            <el-option
              v-for="dict in dict.type.yes_or_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listCitizen, getCitizen, delCitizen, addCitizen, updateCitizen } from "@/api/eim/citizen";
import { listArea } from "@/api/eim/area";

export default {
  name: "Citizen",
  dicts: ['sys_idcard_type', 'sys_oper_type', 'sys_common_status', 'sys_yes_no', 'sys_notice_type', 'sys_user_sex','yes_or_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 省级行政区列表
      provinceList: {},
      // 市级行政区列表
      cityList: {},
      // 区级行政区列表
      districtList: {},
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 外部输入人员表格数据
      citizenList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title_1: "",
      // 是否显示弹出层
      open_1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        sex: null,
        type: null,
        idCard: null,
        phone: null,
        recorder: null,
        inputDate: null,
        inputPosition: null,
        temperature: null,
        isNucleicCheck: null,
        nucleicResult: null,
        fromProvince: null,
        fromCity: null,
        fromDistrict: null,
        isRiskArea: null,
        isHomeDivide: null,
        nowProvince: null,
        nowCity: null,
        nowDistrict: null,
        nowAddress: null,
        chargeDist: null,
        chargeStaff: null,
        isFinish: null,
        finishDate: null,
        ifDiagnosis: null,
        ifCloseContact: null,
        controlStatus: null,
        originProvince: null,
        originCity: null,
        originArea: null,
        originAddress: null,
        parentId:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules_1: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        type: [
          { required: true, message: "证件类型不能为空", trigger: "change" }
        ],
        idCard: [
          { required: true, message: "证件号码不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "手机号/电话号不能为空", trigger: "blur" }
        ],
        inputDate: [
          { required: true, message: "输入时间不能为空", trigger: "blur" }
        ],
        inputPosition: [
          { required: true, message: "输入地点不能为空", trigger: "change" }
        ],
        temperature: [
          { required: true, message: "体温不能为空", trigger: "blur" }
        ],
        isNucleicCheck: [
          { required: true, message: "是否核酸检测不能为空", trigger: "blur" }
        ],
        fromProvince: [
          { required: true, message: "来自省份不能为空", trigger: "change" }
        ],
        fromCity: [
          { required: true, message: "来自某市不能为空", trigger: "change" }
        ],
        fromDistrict: [
          { required: true, message: "来自某区不能为空", trigger: "change" }
        ],
        isRiskArea: [
          { required: true, message: "是否来自风险区不能为空", trigger: "change" }
        ],
        isHomeDivide: [
          { required: true, message: "是否居家健康隔离不能为空", trigger: "blur" }
        ],
        nowProvince: [
          { required: true, message: "现居留某省不能为空", trigger: "blur" }
        ],
        nowCity: [
          { required: true, message: "现居留某市不能为空", trigger: "change" }
        ],
        nowDistrict: [
          { required: true, message: "现居留某区不能为空", trigger: "change" }
        ],
        nowAddress: [
          { required: true, message: "现居住地址不能为空", trigger: "blur" }
        ],
        chargeDist: [
          { required: true, message: "负责社区不能为空", trigger: "change" }
        ],
        chargeStaff: [
          { required: true, message: "负责联系人不能为空", trigger: "change" }
        ],
        isFinish: [
          { required: true, message: "是否接收完毕不能为空", trigger: "blur" }
        ],
        ifDiagnosis: [
          { required: true, message: "是否确诊不能为空", trigger: "change" }
        ],
        ifCloseContact: [
          { required: true, message: "是否密接不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getAreaList();
  },
  methods: {
    /** 行政区列表 */
    getAreaList(){
      this.loading = true;
      this.queryParams.parentId=-1;
      listArea(this.queryParams).then(response => {
        this.provinceList = response.data;
        this.form.fromProvince=this.provinceList[0].areaId
        this.queryProvinceChange()
        this.loading = false;
      });
    },
    /** 搜索省级变化，加载市级 */
    queryProvinceChange(){
      this.loading = true;
      this.queryParams.parentId=this.queryParams.fromProvince;
      listArea(this.queryParams).then(response => {
        this.cityList = response.data;
        this.queryCityChange();
        this.loading = false;
      });
    },
    /** 搜索市级变化，加载区级 */
    queryCityChange(){
      this.loading = true;
      this.queryParams.parentId=this.queryParams.fromCity;
      listArea(this.queryParams).then(response => {
        this.districtList = response.data;
        this.loading = false;
      });
    },
    /** 新增来自省变化*/
    formProvinceChange(){
      this.queryParams.parentId=this.form.fromProvince;
      listArea(this.queryParams).then(response => {
        this.formCityList = response.data;
        this.form.fromCity=this.formCityList[0].areaId
        this.formCityChange();
        this.loading = false;
      });
    },
    /** 新增来自城市变化*/
    formCityChange(){
      this.queryParams.parentId=this.form.fromCity;
      listArea(this.queryParams).then(response => {
        this.formDistrictList = response.data;
        this.form.fromDistrict=this.formDistrictList[0].areaId
        this.loading = false;
      });
    },
    /** 查询外部输入人员列表 */
    getList() {
      this.loading = true;
      listCitizen(this.queryParams).then(response => {
        this.citizenList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel_1() {
      this.open_1 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pid: null,
        name: null,
        sex: null,
        type: null,
        idCard: null,
        phone: null,
        recorder: null,
        inputDate: null,
        inputPosition: null,
        temperature: null,
        isNucleicCheck: null,
        nucleicResult: null,
        fromProvince: null,
        fromCity: null,
        fromDistrict: null,
        isRiskArea: null,
        isHomeDivide: 0,
        nowProvince: null,
        nowCity: null,
        nowDistrict: null,
        nowAddress: null,
        chargeDist: null,
        chargeStaff: null,
        isFinish: 0,
        finishDate: null,
        ifDiagnosis: null,
        ifCloseContact: null,
        controlStatus: null,
        originProvince: null,
        originCity: null,
        originArea: null,
        originAddress: null,
        outerOther: null,
        outerElse: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加外部输入人员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const pid = row.pid || this.ids
      getCitizen(pid).then(response => {
        this.form = response.data;
        this.open_1 = true;
        this.title_1 = "修改外部输入人员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.pid != null) {
            updateCitizen(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open_1 = false;
              this.getList();
              this.reset();
            });
          } else {
            addCitizen(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.reset();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pids = row.pid || this.ids;
      this.$modal.confirm('是否确认删除外部输入人员编号为"' + pids + '"的数据项？').then(function() {
        return delCitizen(pids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('eim/citizen/export', {
        ...this.queryParams
      }, `citizen_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
